<template>
  <div class="item-one" ref="itemOne">
    <div class="title">
      <span>对账单</span>
      <div>
        <el-button type="primary" :disabled='exxxx' @click="merchantexcel()"><i class="el-icon-download" ></i>导出</el-button>
        <!-- <el-button icon="el-icon-refresh"></el-button> -->
      </div>
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
          <div class="leftitem">
            <div class="block">
              <el-date-picker
                v-model="dates"
                type="daterange"
                align="right"
                unlink-panels
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :clearable = 'false'
                >
              </el-date-picker>
              <!-- <el-date-picker
                v-model="dates"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
            </el-date-picker> -->
            </div>
          </div>
        </div>
        <div class="rightBox">
          
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso">搜索</el-button>
            <!-- <el-button icon="el-icon-refresh" type="primary" @click="reset">重置</el-button> -->
          </div>
        </div>
      </div>
       
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
          v-loading="loading"
        >
          <el-table-column type="selection" width="55"></el-table-column>
         <el-table-column align="center" type="index" label="序号"></el-table-column>
         <el-table-column prop="merchantNo" label="商户号"></el-table-column>
         <el-table-column prop="merchantName" label="商户名称"></el-table-column>
         <el-table-column prop="shopNo" label="门店号"></el-table-column>
         <el-table-column prop="shopAlias" label="外部门店号"></el-table-column>
         <el-table-column prop="shopAli" label="口碑门店号"></el-table-column>
         <el-table-column prop="shopName" label="门店名称"></el-table-column>
         <el-table-column prop="dcTotalBalance" label="扫码点餐总交易额"></el-table-column>
         <el-table-column prop="dcTotalCount" label="扫码点餐总交易笔数"></el-table-column>
         <el-table-column prop="dcTotalFee" label="扫码点餐总手续费"></el-table-column>
         <el-table-column prop="dcAliBalance" label="扫码点餐支付宝交易额"></el-table-column>
         <el-table-column prop="dcAliCount" label="扫码点餐支付宝交易笔数"></el-table-column>
         <el-table-column  prop="dcAliFee" label="扫码点餐支付宝手续费"></el-table-column>
         <el-table-column  prop="dcWxBalance" label="扫码点餐微信交易额"></el-table-column>
         <el-table-column  prop="dcWxCount" label="扫码点餐微信交易笔数"></el-table-column>
         <el-table-column  prop="dcWxFee" label="扫码点餐微信手续费"></el-table-column>
         <el-table-column  prop="dcUniBalance" label="扫码点餐云闪付交易额"></el-table-column>
         <el-table-column  prop="dcUniCount" label="扫码点餐云闪付交易笔数"></el-table-column>
         <el-table-column  prop="dcUniFee" label="扫码点餐云闪付手续费"></el-table-column>
         <el-table-column  prop="qtTotalBalance" label="蜻蜓总交易额"></el-table-column>
         <el-table-column  prop="qtTotalCount" label="蜻蜓总交易笔数"></el-table-column>
         <el-table-column  prop="qtTotalFee" label="蜻蜓总手续费"></el-table-column>
         <el-table-column  prop="qtAliBalance" label="蜻蜓支付宝交易额"></el-table-column>
         <el-table-column  prop="qtAliCount" label="蜻蜓支付宝交易笔数"></el-table-column>
         <el-table-column  prop="qtAliFee" label="蜻蜓支付宝手续费"></el-table-column>
         <el-table-column  prop="qtWxBalance" label="蜻蜓微信交易额"></el-table-column>
         <el-table-column  prop="qtWxCount" label="蜻蜓微信交易笔数"></el-table-column>
         <el-table-column  prop="qtWxFee" label="蜻蜓微信手续费"></el-table-column>
         <el-table-column  prop="qtUniBalance" label="蜻蜓云闪付交易额"></el-table-column>
         <el-table-column  prop="qtUniCount" label="蜻蜓云闪付交易笔数"></el-table-column>
         <el-table-column  prop="qtUniFee" label="蜻蜓云闪付手续费"></el-table-column>
         <el-table-column  prop="qtFaceBalance" label="蜻蜓刷脸交易额"></el-table-column>
         <el-table-column  prop="qtFaceCount" label="蜻蜓刷脸交易笔数"></el-table-column>
         <el-table-column  prop="qtFaceFee" label="蜻蜓刷脸手续费"></el-table-column>
          <!-- <el-table-column fixed="right" label="操作" width="120">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="joininfo(scope.row.merchantId)">详细</el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="combined"
            :current-page.sync="cur_page"
          ></el-pagination>
        </div>
      </div>
      <br>
      <br>
      
    </div>
  </div>
</template>

<script>
import { hlspage,merchantstatistics,hlsexcel} from "@/api/api";
export default {
  name:"baseform",
  data: function() {
    return {
      type:'',
      channelType:'',
      exxxx: false,
      tableData: [],
      cur_page: 1,
      cur_size: 10,
      multipleSelection: [],
      visible: false,
      servicearr:[],
      merchantarr:[],
      combined:10,
      pageCount:'',
      dates:[],
      loading: true,
      
    };
  },
  created() {
    const start = new Date();
    start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
    const year=start.getFullYear();
   let month=start.getMonth()+1;
    if(month < 10){
      month = '0'+month
    }
    let date=start.getDate();
    if(date < 10){
      date = '0'+date
    }
    const date1 = year+'-'+month+ '-'+date
    this.dates = [date1,date1]
  
    this.merchantstatistics('1')
    
    
  },
  methods: {
     //修改thead 背景色
     tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
          return "background-color: #F0F0F0;font-weight: 500;font-size:14px;color:#000;";
        }
      },
    
    joininfo(val) {
      // console.log(val)
      this.$router.push({ path: "/businessstatisticsinfo",
          query: { 
                no: val,
                date: this.date,
                channelType: this.channelType
            } 
      });
    },
    // 刷新
    refresh() {
      this.$router.replace({
        path: "/refresh",
        query: {
          t: Date.now()
        }
      });
    },
    // 分页导航
    handleCurrentChange(val) {
      this.merchantstatistics()
      this.cur_page = val;
       this.$nextTick(() => {
         document.querySelectorAll('.content')[0].scrollTop = '0'
      });

    },
    // 分页数量
    sizechange(val){
      this.cur_size = val
       this.merchantstatistics()
       this.$nextTick(() => {
         document.querySelectorAll('.content')[0].scrollTop = '0'
      });
       
    },
    //多选框
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val;
    },
    
    // 搜索
    soso(){
      this.loading =true
       this.cur_page = 1
     
    this.merchantstatistics()
      
    },
    
  
    // 商户交易统计
    merchantstatistics(level){

      // console.log(this.conditions)
      let sosolist = {}
        sosolist ={
          page: this.cur_page,
          size: this.cur_size,
          startDate: this.dates[0],
          endDate: this.dates[1]
          
        }
     
      console.log(sosolist)
      hlspage(sosolist).then(res => {
          // console.log(res);
          if(res.code == 405){
           sessionStorage. removeItem('token')
            this.$router.push('/login');
          }else if(res.code == 200){
            this.merchantarr = res.data
            this.combined = res.pageInfo.recordCount
            this.pageCount = res.pageInfo.pageCount
            this.loading = false
          }else if(res.code == 500){
            this.$message.error(res.message);
          }
          
        });
    },
    
    // 导出
    merchantexcel(){
      this.eeeex = true;
      const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      let sosolist = {}
        sosolist ={
          page: this.cur_page,
          size: this.cur_size,
          startDate: this.dates[0],
          endDate: this.dates[1]
        }
       hlsexcel(sosolist).then(res => {
          if(res.code == 405){
            sessionStorage. removeItem('token')
            this.$router.push('/login');
             loading.close();
             this.exxxx = false;
          }else if(res.code == 200){
            let elink = document.createElement('a');
            elink.href = res.data;
            elink.click();
            this.exxxx = false;
            loading.close();
            
          }else{
            this.$message.error(res.message);
            loading.close();
            this.exxxx = false;
          }
        })


    }
  }
};
</script>
<style scoped lang='less'>
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 50%;
}
.tableBox {
  margin-top: 20px;
}
.servicename{
  width: 43%;
}
.servicename1{
  width: 60%;
}
.servicelevel{
  width: 23.5%;
}
.width20{
    width: 20%;
}
.red {
  color: #f9607d;
}
.blue{
    color: #01AAEF;
}
.stitle{
    padding: 5px 0;
    font-size: 18px;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #374459;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
  .statisticalitem{
      flex: 1;
      text-align: center;
      border-right: 1px solid rgba(255, 255, 255, 0.445);
      font-size: 13px;
      line-height: 180%;
      &:nth-last-child(1){
          border-right: none;
      }
      .red {
        color: #f9607d;
        font-size: 18px;
      }
      .blue{
            color: #01AAEF;
            font-size: 18px;
        }
  }
}
// .BDname{
//   width: 20%;
// }
</style>